package com.woniuxy.stage3demo.mapper.kang;

import com.woniuxy.stage3demo.bean.chenyuxuanBean.StaffBean;
import com.woniuxy.stage3demo.bean.kang.CustomerBean;
import com.woniuxy.stage3demo.pageHelper.PageRequest;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

@Mapper
public interface CustomerMapper {
    /**
     * 新增客服
     * @param customerBean
     * @return
     */
    @Insert("insert into customer (customer_name,remark,del_flag,staff_id,create_time,last_login_time,status) values " +
            "(#{c.customerName},#{c.remark},0,#{c.staffBean.id},now(),now(),0)")
    int addCustomer(@Param("c") CustomerBean customerBean);

    /**
     * 获取一个客服
     * @param id
     * @return
     */
    @Results({
        @Result(id = true,property = "id",column = "id",javaType = Long.class),
        @Result(property = "customer_name",column = "customerName",javaType = String.class),
        @Result(property = "remark",column = "remark",javaType = String.class),
        @Result(property = "staffBean",column = "staff_id" ,javaType = StaffBean.class,one=@One(select = "com.woniuxy.stage3demo.mapper.chenyuxuanMapper.StaffMapper.findStaffById",fetchType = FetchType.LAZY))
    })
    @Select("select customer_name,remark,staff_id from customer where id = #{id} and del_flag = '0'")
    CustomerBean getOneById(@Param("id") int id);

    /**
     * 删除客服，删除标记的更改
     * @param id
     * @return
     */
    @Update("update customer set del_flag = 1 where id = #{id}")
    int deleteCustomer(@Param("id") Long id);

    /**
     * 修改客服
     * @param customerBean
     * @return
     */
    int updateCustomer(@Param("c") CustomerBean customerBean);

    /**
     * 分页查询
     * @param pageRequest
     * @return
     */
    List<CustomerBean> findLimit(@Param("p") PageRequest pageRequest);
}
